window.onload=function () {
    $("#userName").on("blur",function () {
        let url="user/selectname";
        let  date={userName:$(this).val()}
        $.post(url,date,function (map) {
            if (map.state==1){
                $("#userName").val("");
                mizhu.alert( '' ,  '该用户已注册' );
            }
        },"json")
    })


    $("#userPsd").on("blur",function (){
        let s = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/;
        if (!s.test($("#userPsd").val())){
            mizhu.alert( '' ,  '密码必须8-16位的字母和数字组成' );
            $("#userPsd").val("");
        }
    });


    $("#userPhoto").on("blur",function (){
        let s = /[0-9a-zA-Z_]{0,19}@[0-9a-zA-Z]{1,13}\.[com,cn,net]{1,3}/;
        if (!s.test($("#userPhoto").val())){
            mizhu.alert( '' ,  '请输入正确邮箱格式' );
            $("#userPhoto").val("");
        }
    });





    $("#userPhone").on("blur",function (){
        let s = /(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/;
        if (!s.test($("#userPhone").val())){
            mizhu.alert( '' ,  '电话' );
            $("#userPhone").val("");
        }
    });


    $("#tijiao").on("click",function () {
        if ($("#userPsd").val()==""){
            mizhu.alert( '' ,  '请输入密码' );
        }
        else if ($("#userName").val()==""){
            mizhu.alert( '' ,  '请输入密码' );
        }else {
            let formData1 = new FormData(document.getElementById("myform"));
            $.ajax({
                type: 'POST',   //上传文件必须使用post
                url: url,
                data: formData1, //需要传输的数据
                dataType:'json',
                processData: false, // 告诉jquery要传输data对象
                contentType: false,   // 告诉jquery不需要增加请求头对于contentType的设置
                success: function (resp) { //如果上传成功,就执行
                    if(resp.state==1){
                        window.location.replace("login.html");

                    }else{
                        layer.msg(resp.mes);
                    }
                }
                ,error:function (arg) { //如果上传失败,就执行
                    console.log("上传失败执行"+arg)
                }
            });
        }

    })





}